﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//....................
namespace QLKTX1._0.DAO
{
    class SinhVienPhongODAO
    {
        public static List<SinhVien_PhongODTO> dsSinhVienPhongO()
        {
            List<SinhVien_PhongODTO> dsSinhVienPhongO = new List<SinhVien_PhongODTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM sinhVien_phongO");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
               // ChiTietKhungGiaNhaDTO ctkgn = new ChiTietKhungGiaNhaDTO();
                SinhVien_PhongODTO svpo = new SinhVien_PhongODTO();

                SinhVienDTO sv = new SinhVienDTO();
                sv.MaSoTheNoiTru = dt.Rows[i]["maSoTheNoiTru"].ToString();

                PhongODTO po = new PhongODTO();
                po.MaPhongO = Int32.Parse(dt.Rows[i]["maPhongO"].ToString());

                svpo.MaSoTheNoiTru = sv;
                svpo.MaPhongO = po;
                svpo.NgayVaoO = DateTime.Parse(dt.Rows[i]["ngayVaoO"].ToString());
                svpo.TinhTrangTraPhong = Int32.Parse(dt.Rows[i]["tinhTrangTraPhong"].ToString());


                dsSinhVienPhongO.Add(svpo);
            }
            return dsSinhVienPhongO;
        }
        //ham them
        public static bool themSinhVien_Phong(SinhVien_PhongODTO s)
        {
            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO sinhVien_phongO(maSoTheNoiTru,maPhongO,ngayVaoO,tinhTrangTraPhong) VALUES('" + s.MaSoTheNoiTru .MaSoTheNoiTru  + "','" + s.MaPhongO.MaPhongO  + "','" + s.NgayVaoO  + "','" + s.TinhTrangTraPhong  + "')");
        }
        //Ham Delete
        public static bool xoaSinhVien_Phong(SinhVien_PhongODTO s)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM sinhVien_phongO WHERE maSoTheNoiTru='" + s.MaSoTheNoiTru.MaSoTheNoiTru + "'and maPhongO='" + s.MaPhongO.MaPhongO + "'");
        }
        //Ham Update
        public static bool capNhatSinhVien_Phong(SinhVien_PhongODTO s)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE chiTiet_khungGiaNha set ngayVaoO='" + s.NgayVaoO + "',tinhTrangTraPhong="+s.TinhTrangTraPhong +"  WHERE maSoTheNoiTru='" + s.MaSoTheNoiTru.MaSoTheNoiTru + "'and maPhongO='" + s.MaPhongO.MaPhongO + "'");
        }
    }
}
